package com.itheima.sparkml.exercise

import org.apache.spark.SparkConf
import org.apache.spark.sql.SparkSession

object _5LibSvmLoaderSQL {
  def main(args: Array[String]): Unit = {
    val sparkConf=new SparkConf().setAppName("_5LibSvmLoaderSQL").setMaster("local[*]")
    val spark=SparkSession.builder().config(sparkConf).getOrCreate()
    spark.sparkContext.setLogLevel("WARN")
    val dataPath="D:\\test\\data\\iris_libsvm.txt"
    val df = spark.read.format("libsvm").load(dataPath)
    //* 3-打印Schema
    df.printSchema()
    //    root
    //    |-- label: double (nullable = true)
    //    |-- features: vector (nullable = true)
    //* 4-打印数据类型
    df.show(3, false)
    //    +-----+-------------------------------------------------------+
    //    |label|features                                               |
    //    +-----+-------------------------------------------------------+
    //    |1.0  |(4,[0,1,2,3],[-0.555556,0.25,-0.864407,-0.916667])     |
    //    |1.0  |(4,[0,1,2,3],[-0.666667,-0.166667,-0.864407,-0.916667])|
    //    |1.0  |(4,[0,2,3],[-0.777778,-0.898305,-0.916667])            |
    //    +-----+-------------------------------------------------------+
  }
}
